#!/usr/bin/env python
# encoding: utf-8
# @author: LANG
from typing import Union, Type
from selenium.webdriver import *

import settings


class BrowserTypeError(Exception):

    def __init__(self, _type) -> None:
        '''
        类型
        :param _type:
        '''
        self._type = _type

    def __str__(self) -> str:
        return  f"unsupported browser type {self._type}"


class Browser:


    IMP_TIME = 10  # 隐式等待时间

    WINDOW_SIZE = (1024, 900)  # 所有浏览器的尺寸

    PAGE_LOAD_TIME_OUT = 20  # 页面 加载的超时时间

    SCRIPT_TIME_OUT = 20  # 脚本中，可以直接调用js定位元素

    def __init__(self, driver_path: str = settings.CHROME_DRIVER_PATH,
                 browser_type: Type[Union[Firefox, Chrome]] = Chrome,
                 browser_option: Type[Union[FirefoxOptions, ChromeOptions]] = ChromeOptions) -> None:

        if  not isinstance(driver_path ,str):
            raise TypeError
        if not issubclass( browser_type, (Firefox, Chrome)):
            raise  BrowserTypeError(browser_type)
        if  not issubclass(browser_option , (FirefoxOptions, ChromeOptions)):
            raise  BrowserTypeError(browser_option)

        self._browser_type = browser_type
        # # 驱动程序的位置
        self._driver_path = driver_path
        # # 浏览器的其他选项
        self._browser_option = browser_option


    @property
    def options(self):
        '''
        子类需要覆盖。用来获取对应浏览器的  options对象
        :return:
        '''

        return

    @property
    def browser(self):
        '''
        子类需要覆盖，获取对应的 浏览器类型
        :return:
        '''
        return
